package org.example.Server.controller.notice;

import lombok.extern.slf4j.Slf4j;
import org.example.Server.model.notice.NoticeDTO;
import org.example.Server.service.notice.NoticeService;
import org.example.Server.utils.ResultAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/youxich/notice")
public class NoticeController {
    @Autowired
    NoticeService noticeService;

    /**
     * 教师发布通知（统一或者分班
     * @param noticeDTO
     */
    @PostMapping
    public ResultAPI addnotice(@RequestBody NoticeDTO noticeDTO) {
        log.info("addnotice"+noticeDTO);
        return noticeService.addnotice(noticeDTO);
    }

    /**
     * 获取统一或分班发布的通知列表（ALL
     * @param semester_id
     * @return
     */
    @GetMapping
    public ResultAPI getNoticeList(@RequestParam Integer semester_id) {
        return noticeService.getNoticeList(semester_id);
    }

    /**
     * 教师更新已发布通知（统一或者分班
     * @param noticeDTO
     * @return
     */
    @PutMapping
    public ResultAPI updateNotice(@RequestBody NoticeDTO noticeDTO) {
        log.info("update notice"+noticeDTO);
        return noticeService.updateNotice(noticeDTO);
    }

    /**
     * 删除通知
     * @param notice_id
     * @return
     */
    @DeleteMapping("/{notice_id}")
    public ResultAPI deleteNotice(@PathVariable Integer notice_id) {
        log.info("delete notice"+notice_id);
        return noticeService.deleteNotice(notice_id);
    }
}
